package org.tp.framework.filter;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.tp.framework.constant.ExceptionConstant;
import org.tp.framework.exception.TPFrameworkException;
import org.tp.framework.util.StringUtils;

/**
 * 监听初始化
 */
public class InitListern implements ServletContextListener {

    /**
     * 销毁
     *
     * @param event
     */
    @Override
    public void contextDestroyed(ServletContextEvent event) {

    }

    /**
     * 初始化
     *
     * @param event
     */
    @Override
    public void contextInitialized(ServletContextEvent event) {
        String inintPackage = event.getServletContext().getInitParameter("scanPackage");
        if (StringUtils.isEmpty(inintPackage)) {
            throw new TPFrameworkException(ExceptionConstant.INIT_PACKAGE_NAME_ERROR_CODE,
                    ExceptionConstant.INIT_PACKAGE_NAME_ERROR_MSG);
        }

        try {
            FrameworkInit.init(inintPackage);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

    }

}
